<?php $this->load->view('layout/header');?>
<div class="supplier-content-page">
    <div class="supplierTest">
        <div class="product-test-h5">
            <ul class="breadcrumb">
                <li><a href="javascript:;">商品管理</a></li>
                <li><a href="<?php echo site_url('tourismgoodsbase/grid')?>">宝贝管理</a></li>
                <li class="active"><a href="<?php echo site_url('tourismgoodsbase/addstep1')?>">添加宝贝</a></li>
            </ul>
            <?php echo execute_alert_message() ?>
            <form action="<?php echo site_url('tourismgoodsbase/addstep2');?>" method="get">
                <input type="hidden" name="class_a">
                <input type="hidden" name="class_b">
                <input type="hidden" name="class_c">
                <div class="inline-style">
                    <p>选择类目</p>
                    <div class="cc-listwrap">
                        <ul class="cc-list">
                            <li class="cc-list-item">
                                <div class="cc-cbox">
                                    <ul class="cc-cbox-cont" id="class_a">
                                        <?php foreach($cate as $key=>$item): ?>
                                        <li class="cc-cbox-item" key="<?php echo $item->id ?>">
                                            <?php echo $item->name?>
                                            <i class="glyphicon glyphicon-menu-right"></i>
                                        </li>
                                        <?php endforeach;?>
                                    </ul>
                                </div>
                            </li>
                            <li class="cc-list-item">
                                <div class="cc-cbox">
                                    <ul class="cc-cbox-cont" id="class_b"> </ul>
                                </div>
                            </li>
                            <li class="cc-list-item">
                                <div class="cc-cbox">
                                    <ul class="cc-cbox-cont" id="class_c"> </ul>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div class="cate-path">
                        <dl>
                            <dt>您当前选择的是：</dt>
                            <dd class="category-path"></dd>
                        </dl>
                    </div>
                </div>
                <div class="inline-next">
                    <button type="submit" class="btn btn-info">下一步</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
$(document).ready(function(){
    $('#class_a').on('click', 'li', function(){
        var key = $(this).attr('key');
        $(this).addClass('cc-cbox-item-check').siblings('li').removeClass('cc-cbox-item-check');
        $('#class_c').html('');
        $('input[name=class_a]').val(key);
        $('input[name=class_b], input[name=class_c]').val('');
        ajax_class(key, $('#class_b'));
    });
    $('#class_b').on('click', 'li', function(){
        var key = $(this).attr('key');
        $(this).addClass('cc-cbox-item-check').siblings('li').removeClass('cc-cbox-item-check');
        $('input[name=class_b]').val(key);
        $('input[name=class_c]').val('');
        ajax_class(key, $('#class_c'));
    });
    $('#class_c').on('click', 'li', function(){
        var key = $(this).attr('key');
        $(this).addClass('cc-cbox-item-check').siblings('li').removeClass('cc-cbox-item-check');
        $('input[name=class_c]').val(key);
        $.ajax({
            url: hostUrl()+'/tourismgoodscategory/ajax_category_select/' + key,
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                $('.category-path').html(data.cate);
                var record = data.record;
            }
        });
    })
    function ajax_class(key, obj)
    {
        $('#category_id').val(key);
        obj.html('');
        $.ajax({
            url: hostUrl()+'/tourismgoodscategory/ajax_category_select/' + key,
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                $('.category-path').html(data.cate);
                var record = data.record;
                for (var i = 0; i < record.length; i++) {
                    var liObj = $('<li class="cc-cbox-item" key="'+record[i].id+'">'+record[i].name+'<i class="glyphicon glyphicon-menu-right"></i> </li>');
                    liObj.appendTo(obj);
                }
            }
        });
    }
});
</script>